package com.onlinelearn.userservice.service;

import com.onlinelearn.userservice.model.UserPreference;
import com.onlinelearn.userservice.repository.UserPreferenceRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserPreferenceService {
    @Autowired
    private UserPreferenceRepository userPreferenceRepository;

    public UserPreference updateUserPreference(Long userId, UserPreference preference) {
        preference.setUserId(userId);
        return userPreferenceRepository.save(preference);
    }

    public UserPreference getUserPreference(Long userId) {
        return userPreferenceRepository.findByUserId(userId)
            .orElse(new UserPreference(userId));
    }
} 